<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "" "">
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:w="http://www.apusic.com/jsf/widget" xmlns:layout="http://www.apusic.com/jsf/layout"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:ajax="http://www.apusic.com/jsf/ajax"
	renderKitId="AJAX" xmlns:epm="http://www.bp.com.cn/epm">
	<w:head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<w:stylesheet src="/css/kmp4.css" type="text/css"></w:stylesheet>
		<w:script src="/javascript/k4.js" type="text/javascript" language="UTF-8"></w:script>
		<script>
			//<![CDATA[
			function show(v, m, r, rIndex){
             //var r=schnarioGrid.getSelectionModel().getSelected();
             var id=r.get('id');
             var url="#{facesContext.externalContext.requestContextPath}/modules/eop/showSchnario.faces?id="+id;
             
             return "<a href=\"javascript:addCenterLayoutTab('showSchnarioTab','查看预案','"+url+"')\">"+v+"</a>";
             //addCenterLayoutTab('showSchnarioTab','查看预案', url);
    	   }
    	   function showSch(grid){
    	     var r=grid.getSelectionModel().getSelected();
    	     if(r == null){
    			alert('请选择一条记录!');
    			return false;
    		 }
    		 var url="#{facesContext.externalContext.requestContextPath}/modules/eop/showSchnario.faces?id="+r.get('id');;
    		 addCenterLayoutTab('showSchnarioTab','查看预案',url);
    	   }
    	   
    	   function operationFormatter(v, m , r, rIndex){
		 	  var dirId = r.get('id');
		 	  //var content=r.get('content');
		 	  var isPublish=r.get('publishState');
		 	  //script='javascript:showCon(\''+dirId+'\',\''+content+'\')';
		      //var con='<a href="'+script+'">文本</a>';
		 	  
			  //var con = "<a href='javascript:showCon(\""+dirId+"\",\""+content+"\")'>文本</a>";
			  
			  var con = "<a href='javascript:showContent(\""+dirId+"\")'>文本</a>";
			  var att = "<a href='javascript:showAtt(\""+dirId+"\")'>附件</a>";
			  var flow = "<a href='javascript:showFlow(\""+dirId+"\")'>流程</a>";
			  var pub = "<a href='javascript:publishSr(\""+dirId+"\")'>发布</a>";
			  var ret;
			  if(isPublish=='true'){
			    ret =con+"|"+att+"|"+flow;
			  }else{
			    ret =con+"|"+att+"|"+flow+"|"+pub;
			  }
			  
			  return ret;
		   }
		   function showContent(id){
		      //shcIdJsvar.setValue(id);
		      showRepaireJsvar.addParam('id', id);
		      showRepaireJsvar.submit();
		   }
		   
		   
		   
		   function showCon(id,content){
		     if(content==null||content==''||content=='null'){
		        conJsvar.setValue('');
		      }else{
		        conJsvar.setValue(content);
		      }
		      shcIdJsvar.setValue(id);
		     //文本
		     repaireWinJsvar.show();
		   }
		   function showAtt(id){
		     //附件
		     var beanClass='com.eop.entity.Schnario';
		     var attachmentType='schAtt';
		     var url='#{facesContext.externalContext.requestContextPath}/component/listAttachment.faces?beanId='+id+'&beanClass='+beanClass+'&attachmentType='+attachmentType;
		     showRelation('附件',url);
		   }
		   function showFlow(id){
		     //流程
		     var beanClass='com.eop.entity.Schnario';
		     var attachmentType='schFlow';
		     var url='#{facesContext.externalContext.requestContextPath}/modules/eop/listFlow.faces?beanId='+id+'&beanClass='+beanClass+'&attachmentType='+attachmentType;
		     showRelation('流程',url);
		   }
		   
		   function publishSr(id){
		      publishJsvar.addParam('id', id);
		      publishJsvar.submit();
		   }
		   
		   function freshme(){
 		    var store=schnarioGridJsvar.getStore();
		    store.reload(store.lastOptions);
     	   }
     	   
     	   function checkDelete(){
		 	var r = schnarioGridJsvar.getSelectionModel().getSelected();
    		if(r == null){
    			alert('请选择一条记录!');
    			return false;
    		}
    		return showConfirm('确认删除吗?');
		   }
		   
		   function showRelation(title,url){
			iframe_rd.location.href=url;
			window_rd.setTitle(title);
			window_rd.show();
		}
		function closeWindow(jsvar){
			window_rd.hide();
			refreshData(jsvar);
		}
		        
        function refreshData(){
			window_rd.hide();
			window.location.reload();
		 }
    	   //]]>
    	</script>
	</w:head>
	<w:page title="预案一览">
		<layout:panel border="false" autoHeight="true" header="false" styleClass="k4-form">
			<layout:panel border="false" autoHeight="true" autoWidth="true" styleClass="k4-view-toolbar">
				<w:form>
					<w:toolBar>
						<w:button label="新增预案" image="/images/create.gif" id="addSchnario" immediate="true"
							onclick="javascript:addCenterLayoutTab('addSchnarioTab','新增预案','#{facesContext.externalContext.requestContextPath}/modules/eop/addSchnario.faces');" />
						<w:separator />
						<w:button label="编辑预案" image="/images/edit.gif" id="eidtSchnario" immediate="true" />
						<w:separator />
						<w:button label="删除预案" image="/images/delete.gif" onclick="return checkDelete();"
							id="deleteSchnario" immediate="true" />
					</w:toolBar>
				</w:form>
			</layout:panel>
			<layout:panel>
				<w:form>
					<layout:panelGrid width="100%" columns="4" cellpadding="0" cellspacing="1"
						styleClass="k4-view-searchForm">
						<layout:cell styleClass="k4-form-fieldtitle" style="height: 0px;">
						</layout:cell>
						<layout:cell styleClass="k4-form-fieldvalue" style="height: 0px;">
						</layout:cell>
						<layout:cell styleClass="k4-form-fieldtitle" style="height: 0px;">
						</layout:cell>
						<layout:cell styleClass="k4-form-fieldvalue" style="height: 0px;">
						</layout:cell>
						<layout:cell styleClass="k4-form-fieldtitle">
							<h:outputText value="预案名称"></h:outputText>
						</layout:cell>
						<layout:cell styleClass="k4-form-fieldvalue">
							<w:textField id="schnarioName" jsvar="schnarioNameJsvar" styleClass="k4-form-textfield"></w:textField>
						</layout:cell>
						<layout:cell colspan="2" styleClass="k4-form-triple-fieldvalue">
							<layout:panelGrid>
								<layout:cell>
									<w:button id="search" label="搜索"
										image="#{facesContext.externalContext.requestContextPath}/images/search.gif" />
								</layout:cell>
								<layout:cell>
									<w:button id="reset" label="重置"
										image="#{facesContext.externalContext.requestContextPath}/images/clear.gif" />
								</layout:cell>
							</layout:panelGrid>
						</layout:cell>
					</layout:panelGrid>
				</w:form>
			</layout:panel>
			<w:dataGrid id="schnarioGrid" toolBarPosition="bottom" rows="10" paged="true" forceFit="true"
				border="false" styleClass="k4-view-datagrid" showRowNumber="true" autoHeight="true"
				singleSelect="true" selectionModel="#{selectionModel.checkbox}" jsvar="schnarioGridJsvar"
				ondblclick="showSch(this);">
				<w:outputColumn id="id" header="id" hidden="true"></w:outputColumn>
				<w:outputColumn id="srCode" header="编码" width="80"></w:outputColumn>
				<w:outputColumn id="version" header="版本" width="80"></w:outputColumn>
				<w:outputColumn id="srName" header="预案名称" width="122" clientFormatter="show"></w:outputColumn>
				<w:outputColumn id="srType" header="类型" width="80" converter="commonKeyFormatter"></w:outputColumn>

				<w:outputColumn id="srRangeBigType" header="适用范围大类" width="80" converter="commonKeyFormatter"></w:outputColumn>
				<w:outputColumn id="srRangeThinType" header="适用范围细类" width="80" converter="commonKeyFormatter"></w:outputColumn>

				<w:outputColumn id="createUser" header="创建者" width="80" converter="usernameFormatter"></w:outputColumn>
				<w:outputColumn id="createDate" header="创建时间" width="100" converter="dateMinuteFormatter"></w:outputColumn>
				<w:outputColumn id="operation" header="操作" width="120" clientFormatter="operationFormatter" />

				<w:outputColumn id="publishState" header="是否发布" hidden="true" />
				<w:outputColumn id="content" header="文本" hidden="true"></w:outputColumn>
				<w:pagingToolbar for="schnarioGrid" displayInfo="true" displayMsg="显示 {0} - {1}，共 {2} 条" />
			</w:dataGrid>
		</layout:panel>
		<ajax:submitAction id="publish" jsvar="publishJsvar"></ajax:submitAction>

		<layout:window jsvar="window_rd" modal="true" show="false" autoScroll="true" width="720"
			height="380">
			<w:iframe id="iframe_rd" name="iframe_rd" style="width:100%;height:99%;" frameborder="0"></w:iframe>
		</layout:window>

		<layout:window id="repaireWin" jsvar="repaireWinJsvar" title="预案文本" height="380" width="690">
			<layout:panel height="390" width="690">
				<w:form>
					<w:toolBar>
						<w:button id="saveRepair" value="保存"
							image="#{facesContext.externalContext.requestContextPath}/images/save.gif"></w:button>
						<w:separator></w:separator>
						<w:button id="cancelRepair" value="取消"
							image="#{facesContext.externalContext.requestContextPath}/images/cancel.gif"
							onclick="repaireWinJsvar.hide();" alwaysSubmit="false"></w:button>
					</w:toolBar>
					<layout:panelGrid columns="2">
						<layout:cell styleClass="k4-form-fieldtitle">
							<h:outputText value="文本"></h:outputText>
						</layout:cell>
						<layout:cell styleClass="k4-form-fieldvalue">
							<w:simpleHtmlEditor height="290" width="550" id="reContent" jsvar="conJsvar"
								fontFamilies="['宋体','隶书','楷体','仿宋','黑体','华文彩云','华文琥珀','幼圆','Times New Roman','微软雅黑','楷体_GB2312','仿宋_GB2312']"></w:simpleHtmlEditor>
						</layout:cell>
						<layout:cell style="display: none">
						    <w:textField id="schId" jsvar="shcIdJsvar"></w:textField>
						</layout:cell>
					</layout:panelGrid>
				</w:form>
			</layout:panel>
		</layout:window>
		<ajax:submitAction id="showRepaire" jsvar="showRepaireJsvar"></ajax:submitAction>
	</w:page>
</f:view>